this.rjapmn = this.rjapmn || {};

(function(){;
	rjapmn.data = {};

	//ie6判定
	rjapmn.data.ie6 = (uaInfo.isIe && uaInfo.ieVr <= 6) ? true : false;
	rjapmn.data.timer_chara;

	//----------------------------------------------------------------------------
	// INIT - Event
	//----------------------------------------------------------------------------
	rjapmn.init = function(){
		rjapmn.initEvent("btn");
	}

	rjapmn.initEvent = function(str){
		switch(str){
			case "btn":
				rjapmn.initBtnMap();
			break;

		}
	}

	//----------------------------------------------------------------------------
	// INIT - BtnMap
	//----------------------------------------------------------------------------
	rjapmn.initBtnMap = function(){
		var _href;
		var _img = '#contentMain .maparea li a img';

		//init rollover
		rjapmn.initBtnMapRollOver(_img);

		//init pjax
		$(document).on('click', 'a.pjax', function(e) {

			//ie6の場合、推移先のURLの最後に?が付加される不具合があるので、
			//判別して、pjaxを動作させない。
			if(!rjapmn.data.ie6){
				e.preventDefault();
				_href = $(this).attr('href');

				$('.maparea').animate({
					opacity : 0
				}, rjapmn.data.INTERVAL, 'easeOutQuad', function() {
					$.pjax({
						url: _href,
						container : '.maparea',
						fragment : '.maparea',
						timeout : 30000
					});
				});
			}

			return false;
		});

		//end pjax
		$(document).on('pjax:end', function() {
			$('.maparea').animate({
				opacity : 1
			}, rjapmn.data.INTERVAL, 'easeOutQuad', function() {
				rjapmn.initBtnMapRollOver(_img);
			});
		});

		$('.maparea li a').on('click', function(e) {
			e.preventDefault();

			_href = $(this).attr('href');
			document.location = _href;

			//sp or tablet用　アクセス時画像をoffに戻す
			$(this).attr('src', $("img", this).attr('src').replace('_on', '_off'));
		});


		//sp or tablet用　タイミングによっては切り替わらないので、再度記述
		$('.maparea li a img').on('click', function(e) {
			$(this).attr('src', $(this).attr('src').replace('_on', '_off'));
		});
	}

	//----------------------------------------------------------------------------
	// INIT - RollOver Replace
	//----------------------------------------------------------------------------
	rjapmn.initBtnMapRollOver = function(str){
		$(str).hover(function(){
			rjapmn.onImgReplace.on($(this));
			rjapmn.onChangeCharactor("on", $(this).parent().parent().index());
		}, function(){
			rjapmn.onImgReplace.off($(this));
			rjapmn.onChangeCharactor("off", $(this).parent().parent().index());
		});
	}

	//----------------------------------------------------------------------------
	// EVENT - CHANGE CHARACTOR
	//----------------------------------------------------------------------------
	rjapmn.onChangeCharactor = function(mode,n){
		/*$(".maparea .bear_area .chara").css({opacity:1});*/

		if(mode == "on"){
			var numX = n%5;
			var numY = n/5 | 0;
			var _posX = 350*numX*-1;
			var _posY= 350*numY*-1;

			$('.maparea .bear_area .chara').css({
				left: _posX+"px",
				top: _posY+"px"
			});
			$('.maparea .bear_area .chara').stop().animate({opacity : 1}, 20, 'easeOutQuad');

			rjapmn.onTimerCharaControl(false);
			rjapmn.onCharaShowEvent(false);
		}else{
			$('.maparea .bear_area .chara').stop().animate({opacity : 0}, 20, 'easeOutQuad', function(){
				$('.maparea .bear_area .chara').css({
					left: "0px",
					top: "350px"
				});
			});

			rjapmn.onTimerCharaControl(true);
		}
	}
	/*$(".bear_area").css("backgroundPosition", _posX+"px "+_posY+"px");
	$('.bear_area').stop().animate({opacity : 1}, 20, 'easeOutQuad');}*/

	rjapmn.onTimerCharaControl = function(b){
		if(b){
			if(rjapmn.data.timer_chara){
				clearInterval(rjapmn.data.timer_chara);
				rjapmn.data.timer_chara = null;
			}
			rjapmn.data.timer_chara = setInterval(function(){
				rjapmn.onCharaShowEvent(true);
			},500);
		}else{
			if(rjapmn.data.timer_chara){
				clearInterval(rjapmn.data.timer_chara);
				rjapmn.data.timer_chara = null;
			}
		}
	}

	rjapmn.onCharaShowEvent = function(b){
		if(b){
			rjapmn.onTimerCharaControl(false);
			$('.maparea .bear_area').css("backgroundPosition", "0px 0px");
		}else{
			$('.maparea .bear_area').css("backgroundPosition", "0px -350px");
		}
	}

	//----------------------------------------------------------------------------
	// EVENT - SEARCH TYPE
	//----------------------------------------------------------------------------
	rjapmn.onImgReplace = {
		on:function(obj){obj.attr('src', obj.attr('src').replace('_off', '_on'));},
		off:function(obj){obj.attr('src', obj.attr('src').replace('_on', '_off'));}
	}
})();

//----------------------------------------------------------------------------
// INIT
//----------------------------------------------------------------------------
$(document).ready(
	function(){
		rjapmn.init();
	}
);